package com.hmall.item.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.IItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("item")
public class ItemController {

    @Autowired
    private IItemService itemService;

    @GetMapping("list")
    public PageDTO list(Integer page, Integer size) {
        return itemService.list(page, size);
    }
    @GetMapping("{id}")
    public Item getById(@PathVariable Long id) {
        return itemService.getById(id);
    }
    @PostMapping
    public void save(@RequestBody Item item) {
        itemService.save(item);
    }
    @PutMapping("status/{id}/{status}")
    public void updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        itemService.updateStatus(id, status);
    }
    @PutMapping
    public void update(@RequestBody Item item) {
        itemService.updateById(item);
    }
    @DeleteMapping("{id}")
    public void delete(@PathVariable Long id) {
        itemService.removeById(id);
    }
}
